package com.tiejun.ge.common.core.domain;

import com.tiejun.ge.common.core.constant.HttpStatus;
import lombok.Data;

import java.io.Serializable;

/**
 * @program: springboot
 * @description: 请求基本响应体
 * @author: getiejun
 * @create: 2025-07-30 23:13
 **/
@Data
public class R<T> implements Serializable {

    private String msg;

    private T data;

    private int code;

    public R() {
    }

    /**
     * 返回ajax对象
     *
     * @param code 请求code
     * @param msg  请求message
     */
    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 返回R对象
     *
     * @param code 请求 code
     * @param msg  请求 message
     * @param data 请求返回数据
     */

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R success () {
        return new R(HttpStatus.SUCCESS, "操作成功");
    }

    public static R success (Object data) {
        return new R(HttpStatus.SUCCESS, "操作成功", data);
    }

    public static R error (String message) {
        return new R(HttpStatus.ERROR, message, null);
    }

    public static R error (int code, String msg) {
        return new R(code, msg);
    }
}
